package common.fengkai.filepost.utils;

import com.alibaba.fastjson.JSONObject;
import common.fengkai.filepost.VO.getPdfInfo;
import common.fengkai.filepost.VO.pdfFileInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * 模拟电子保单系统发送请求
 */

public class pdfSaveToRestTemplete {
       public static void main(String[] args) throws Exception {
           String url = "http://10.30.48.249/api/seal/signfile";
            //String url = "http://10.29.28.3/api/seal/signfile";
           //String url = "http://10.29.31.60:8888/seal/signfile";
/**
 * "C:\\Users\\carry\\Desktop\\项目资料\\非车简易测试文件\\66801060720200000005.pdf"
* {"File":"xxxxxxxxx",
* "FileName":"xxxxxxxxx",
* "sealNames":["印章名1","印章名2"],
* "printlnerIp":"127.0 .0 .1",
* "positionList":[{"x":"220","y":"220"}],
* "keywordList":[{"keyword":"key"}]}
*/
           RestTemplate rest = new RestTemplate();

           try {
               MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
               //String fileUrl = "http://10.29.27.191:8081/ips-file/third_party_mental_health/00265357154e45d962e4da07c5512145298ef6b4857b0fc64f6c10f7e4b48872f8c352ae0d3c3071d8ddad942e834c5b6b1bf4f03daa2b5687f60e1e4943941163ec004a2fe1e2e26c3172ca70dbe4a616d5d76e7ea5dd99819930efd86f42e8";
               String file = getFile();
               pdfFileInfo pdfFileInfo = getPdfInfo.get();
               pdfFileInfo.setPrintlnerIp("9.3.34.7");
              // pdfFileInfo.setOrgId("336");
               pdfFileInfo.setCopies(1);
               pdfFileInfo.setKeysn("测试测试测试");
               pdfFileInfo.setDuplex("1");
               pdfFileInfo.setFile(file);
               pdfFileInfo.setFileName("0606.pdf");
               JSONObject pdfFileInfoJson = (JSONObject) JSONObject.toJSON(pdfFileInfo);
               System.out.println(pdfFileInfoJson);
               param.add("pdfFileInfo", pdfFileInfoJson);
               //String string = rest.postForObject(url, param, String.class);
               ResponseEntity<String> stringResponseEntity = rest.postForEntity(url, pdfFileInfoJson, String.class);
               System.out.println(stringResponseEntity);
               System.out.println(pdfFileInfoJson.toString());
           } catch (Exception e) {
               e.printStackTrace();
           }


       }

    private static String getFile () throws Exception {
        return Base64util.encodeBase64File("C:\\Users\\carry\\Desktop\\电子保单测试\\更新后signed914.pdf");


    }
}
